package com.test.teach.thread;

//军队线程，模拟了作战双方的进攻
public class ArmyRunnable implements Runnable {
	// volatile保证了线程可以正确的读取其他线程写入的值，可见性
	volatile boolean keeprunning = true;

	@Override
	public void run() {

		while (keeprunning) {
			// 发动五连击
			for (int i = 0; i < 5; i++) {
				System.out.println(Thread.currentThread().getName() + "发动了["
						+ (i + 1) + "]次攻击！！！");

				Thread.yield(); // 让出处理器时间，下次该谁进攻还不一定呢

			}
		}
		System.out.println(Thread.currentThread().getName() + "停止了进攻！");
	}

}
